package Scene1;

import Picture.GameImage;
import Player.MusicPlayer;
import Scene2.PlantPanel;
import Scene4.AnimalPanel2;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Stack;

public class ChoicePanel extends JPanel {
    public Stack<MusicPlayer> stack = new Stack<>();
    Scene1 scene1 = new Scene1();
    EndYU en = new EndYU();
    BufferedImage imgF =  GameImage.get("/Picture/章节一结束语/场景1-小精灵台词图片/1.png");
    BufferedImage imgP = scene1.map.get("scene1-background");
    PlantPanel plantPanel = new PlantPanel();
    AnimalPanel2 animalPanel2 = new AnimalPanel2();
    public int isAll = 0;
    public int flag = 0;
    public int flag2 = 0;
    public volatile int af = 0;
    Tree tree = new Tree();
    Plant1 plant1 = new Plant1();
    MusicPlayer a1 = new MusicPlayer("/music/起始小精灵/a1.mp3");
    MusicPlayer a2 = new MusicPlayer("/music/起始小精灵/a2.mp3");
    MusicPlayer a3 = new MusicPlayer("/music/起始小精灵/a3.mp3");
    MusicPlayer a4 = new MusicPlayer("/music/起始小精灵/a4.mp3");
    MusicPlayer a5 = new MusicPlayer("/music/起始小精灵/a5.mp3");
    MusicPlayer a6 = new MusicPlayer("/music/起始小精灵/a6.mp3");
    MusicPlayer a7 = new MusicPlayer("/music/起始小精灵/a7.mp3");
    MusicPlayer a8 = new MusicPlayer("/music/起始小精灵/a8.mp3");
    MusicPlayer a9 = new MusicPlayer("/music/起始小精灵/a9.mp3");
    MusicPlayer a10 = new MusicPlayer("/music/起始小精灵/a10.mp3");
    MusicPlayer a11= new MusicPlayer("/music/起始小精灵/a11.mp3");
    MusicPlayer a12= new MusicPlayer("/music/起始小精灵/a12.mp3");
    MusicPlayer a13 = new MusicPlayer("/music/起始小精灵/a13.mp3");
    MusicPlayer a14 = new MusicPlayer("/music/起始小精灵/a14.mp3");
    MusicPlayer a15 = new MusicPlayer("/music/起始小精灵/a15.mp3");
    MusicPlayer a16= new MusicPlayer("/music/起始小精灵/a16.mp3");
    MusicPlayer a17= new MusicPlayer("/music/起始小精灵/a17.mp3");
    MusicPlayer a18 = new MusicPlayer("/music/起始小精灵/a18.mp3");
    MusicPlayer a19 = new MusicPlayer("/music/起始小精灵/a19.mp3");
    MusicPlayer a20 = new MusicPlayer("/music/起始小精灵/a20.mp3");




    public ChoicePanel(PlantPanel P,AnimalPanel2 A){
        new Thread(()->{
            while (true){

                if(af==2){
                    a1.stop();

                }
                if(af==3){
                    a2.stop();

                }
                if(af==4){
                    a3.stop();

                }

                if(af==5){
                    a4.stop();

                }
                if(af==6){
                    a5.stop();

                }if(af==7){
                    a6.stop();
                }if(af==8){
                    a7.stop();
                }
                if(af==9){
                    a8.stop();;
                }
                if(af==10){
                    a9.stop();
                }
                if(af==11){
                    a10.stop();
                }
                if(af==12){
                    a11.stop();
                }
                if(af==13){
                    a12.stop();
                }
                if(af==14){
                    a13.stop();
                }if(af==15){
                    a14.stop();
                }if(af==16){
                    a15.stop();
                }if(af==17){
                    a16.stop();
                }if(af==18){
                    a17.stop();
                }if(af==19){
                    a18.stop();
                }if(af==20){
                    a19.stop();
                }
                if(af==21){
                    a20.stop();
                }
            }
        }).start();
        new Thread(()->{
            while (true){
                if(af==1){
                    a1.play();
                }
                if(af==2){
                    a2.play();
                }
                if(af==3){
                    a3.play();
                }
                if(af==4){
                    a4.play();
                }
                if(af==5){
                    a5.play();
                }
                if(af==6){
                    a6.play();
                }if(af==7){
                    a7.play();
                }if(af==8){
                    a8.play();
                }if(af==8){
                    a8.play();
                }
                if(af==9){
                    a9.play();
                }
                if(af==10){
                    a10.play();
                }
                if(af==11){
                    a11.play();
                }
                if(af==12){
                    a12.play();
                }
                if(af==13){
                    a13.play();
                }
                if(af==14){
                    a14.play();
                }if(af==15){
                    a15.play();
                }if(af==16){
                    a16.play();
                }if(af==17){
                    a17.play();
                }if(af==18){
                    a18.play();
                }if(af==19){
                    a19.play();
                }if(af==20){
                    a20.play();
                }
            }
        }).start();
        stack.push(a8);
        stack.push(a7);
        stack.push(a6);
        stack.push(a5);
        stack.push(a4);
        stack.push(a3);
        stack.push(a2);
        animalPanel2 = A;
        plantPanel = P;

        new Thread(()->{

            try {
                while(true) {
                    if(A.allEnd ==1&&P.allEnd==1){
                        isAll=1;
                    }
                    plant1.changeImage();
                    repaint();
                    Thread.sleep(100);
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }



    public void changeFont(){
        imgF = en.stackFont.pop();
    }
    public void changeImg(){
        imgP = en.stackPic.pop();
    }
    public void paint(Graphics g){
        g.drawImage(scene1.map.get("scene1-background"),0,0,null);
        g.drawImage(tree.img,tree.x,tree.y,null);
        g.drawImage(plant1.img,1200,700,null);
        g.drawImage(scene1.map.get("grass"),1100,700,null);
        if(flag==1){
            g.drawImage(scene1.map.get("npc"),-80,450,null);
            g.drawImage(scene1.map.get("聊天框"),250,800,null);
            g.drawImage(GameImage.get("/Picture/Scene1/植物提示语.png"),360,870,null);
        }
        if(flag2==1){
            g.drawImage(scene1.map.get("npc"),-80,450,null);
            g.drawImage(scene1.map.get("聊天框"),250,800,null);
            g.drawImage(GameImage.get("/Picture/Scene1/动物提示语.png"),360,870,null);
        }
        if(isAll==1){
            g.drawImage(imgP,0,0,null);
            g.drawImage(scene1.map.get("npc"),-80,450,null);
            g.drawImage(scene1.map.get("聊天框"),250,800,null);
            g.drawImage(scene1.map.get("箭头"),1200,970,null);
            g.drawImage(imgF,360,840,null);
        }

    }

}
